/*
 * 作者: 侯晓宇
 * 时间: 2017-01-24
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {

	require("jquery");
	require("blur");
	var c = require('app/utils/CommonUtils');
	var EventUtils = require('app/utils/EventUtils');
	var appInfo = require('app/AppInfo');
	var APIUtils = require('app/utils/APIUtils');
	var param = api.pageParam;
	var action = require('./action/CreateRoomCoverFrmAction');
	
	$("#photo_container").height(parseInt(APIUtils.winW()*9/16));
	
	$("#photo_button_wrap").width(parseInt(APIUtils.winW()/2));
	$("#photo_button_wrap").height(parseInt(APIUtils.winW()/2 * 9/16));
	
	$('#photo_background').backgroundBlur({
    	imageURL : '../image/photo_background.jpg',
    	blurAmount : 50,
    	imageClass : 'bg-blur'
	});
	
	$("#photo_button_wrap").click(function(){
		action.addCover()
			.then(function(data){
				if(data){ //camera
					return action.launchCamera();
				}else{ //library
					return action.launchPic();
				}
			})
			.then(function(data){ //clipImage
				return action.clipImage(data);
			})
			.then(function(data){ //finalImage
				action.updateCover(data);
			});
	});
	
	
	$("#photo_button_wrap").show();
	
	
	//用于将选中的值传递给父窗体
	EventUtils.listenGather(function(){
		var msg = action.getCoverVal();
		//本地地址,/var/xxxx/.xxxx.jpg
		EventUtils.sendFrmVal(msg);
	});
	
	if(!c.isNullStr(param.livecoverurl)){
		action.updateCover(c.handleUrl(param.livecoverurl));
	}
	
	
	return;
});